package com.autonavi.collapse.task.model;

import java.util.Date;
import java.util.Map;
import java.util.Objects;

public class TaskConfig {

    public static final int NEW = 0;
    public static final int DISPATCHED = 1;
    public static final int RUNNING = 2;
    public static final int ERROR = 3;
    public static final int FINISH = 4;
    public static final int FAIL = 5;

    private String id;
    private String group;
    private String type;
    private String owner;
    private String beginTime;
    private String endTime;
    private Date createTime;
    private int priority = 0;
    private int status = NEW;
    private ExtendedMap configs;

    public TaskConfig() {
    }

    public TaskConfig(Map<String, ConfigValue> configs) {
        this.configs = new ExtendedMap(configs);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public String getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(String beginTime) {
        this.beginTime = beginTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public ExtendedMap getConfigs() {
        return configs;
    }

    public void setConfigs(ExtendedMap configs) {
        this.configs = configs;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TaskConfig config = (TaskConfig) o;
        return Objects.equals(id, config.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    public String toString() {
        return owner == null ? id : String.format("%s(%s)", id, owner);
    }
}
